{% extends 'news/base.html' %}

{# 标题部分 #}
{% block titleBlock %}
    详情页
{% endblock %}

{# script部分 #}
{% block scriptBlock %}
    <script type="text/javascript" src="../../static/news/js/detail.js"></script>
{% endblock %}

{# 正文部分 #}
{% block contentBlock %}
    <div class="detail_con fl">
        <h3>{{ data.news.title }}</h3>
        <div class="detail_about clearfix">
            <span class="time_souce fl">{{ data.news.create_time }} 来源: {{ data.news.source }}</span>
            <span class="comment fr">{{ data.news.comment_count }}</span>
        </div>

        {# safe 禁用转义，让html标签失效 #}
        {{ data.news.content | safe }}

        <a href="javascript:;" class="collection block-center" style="display: {% if data.is_collected %} none {% else %} block {% endif %}" data-newid="{{ data.news.id }}">收藏</a>
        <a href="javascript:;" class="collected block-center" style="display: {% if data.is_collected %} block {% else %} none {% endif %}" data-newid="{{ data.news.id }}"><span class="out">已收藏</span><span class="over">取消收藏</span></a>

        {# 通过判断用户是否登录来显示评论框 #}
        {% if data.user_info %}
            <form action="" class="comment_form" data-newsid="{{ data.news.id }}">
                <div class="person_pic">
                    <img src="../../static/news/images/cat.jpg" alt="用户图标">
                </div>
                <textarea placeholder="请发表您的评论" class="comment_input"></textarea>
                <input type="submit" name="" value="评 论" class="comment_sub">
            </form>
        {% else %}
            <div class="comment_form_logout">
                登录发表你的评论
            </div>
        {% endif %}

        <div class="comment_count">
            {{ data.news.comments_count }}条评论
        </div>

        <div class="comment_list_con">
            {# 遍历查询出所有的评论 #}
            {% for comment in data.comments %}
                <div class="comment_list">
                    <div class="person_pic fl">

                        {# 判断评论用户是否有头像 #}
                        {% if comment.user.avatar_url %}
                            <img src="{{ comment.user.avatar_url }}" alt="用户图标">
                        {% else %}
                            <img src="../../static/news/images/worm.jpg" alt="用户图标">
                        {% endif %}

                    </div>
                    <div class="user_name fl">用户{{ comment.user.nick_name }}</div>

                    {# 评论内容 #}
                    <div class="comment_text fl">
                        {{ comment.content }}
                    </div>

                    {# 判断是否有父评论 #}
                    {% if comment.parent %}
                        <div class="reply_text_con fl">
                            <div class="user_name2">用户{{ comment.parent.user }}</div>
                            <div class="reply_text">
                                {{ comment.parent.content }}
                            </div>
                        </div>
                    {% endif %}

                    <div class="comment_time fl">{{ comment.create_time }}</div>
                    <a href="javascript:;" class="comment_up {% if comment.is_like %} has_comment_up {% endif %} fr"
                       data-commentid="{{ comment.id }}"
                       data-likecount="{{ comment.like_count }}"
                       data-newsid="{{ comment.news_id }}">
                        {% if comment.like_count > 0 %}
                            {{ comment.like_count }}
                        {% else %}
                            赞
                        {% endif %}
                    </a>
                    <a href="javascript:;" class="comment_reply fr">回复</a>
                    <from class="reply_form fl" data-newsid="{{ comment.news_id }}" data-commentid="{{ comment.id }}">
                        <textarea  class="reply_input"></textarea>
                        <input type="submit" name="" value="回复" class="reply_sub fr">
                        <input type="reset" name="" value="取消" class="reply_cancel fr">
                    </from>
                </div>
            {% endfor %}

        </div>
    </div>
{% endblock %}

{# 作者信息 #}
{% block authorBlock %}
    <div class="author_card">
        {% if data.news.author.avatar_url %}
            <a href="#" class="author_pic"><img src="{{ data.news.author.avatar_url }}" alt="author_pic"></a>
        {% else %}
            <a href="#" class="author_pic"><img src="../../static/news/images/user_pic.png" alt="author_pic"></a>
        {% endif %}

        <a href="/user/other?id={{ data.news.author.id }}" class="author_name">{{ data.news.author.nick_name }}</a>
        <div class="author_resume">{{ data.news.author.signature }}</div>
        <div class="writings"><span>总篇数</span><b>{{ data.news.author.news_count }}</b></div>
        <div class="follows"><span>粉丝</span><b>{{ data.news.author.followers_count }}</b></div>
        <a href="javascript:;" class="focus fr" data-userid="{{ data.news.author.id }}" style="display: {% if data.is_followed %} none {% else %} block {% endif %};">关注</a>
        <a href="javascript:;" class="focused fr" data-userid="{{ data.news.author.id }}" style="display: {% if data.is_followed %} block {% else %} none {% endif %};"><span class="out">已关注</span><span class="over">取消关注</span></a>
    </div>
{% endblock %}
